//
//  ViewController.m
//  CycleControlFunction
//
//  Created by ddy on 2018/8/6.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "ViewController.h"
#import "cycleFunctionExtend.h"
#import "OtherViewController.h"
@interface ViewController ()

@end
@implementation ViewController

- (void)clickRight {
    OtherViewController *rightVC = [[OtherViewController alloc]init];
    [self.navigationController pushViewController:rightVC animated:YES];
}
- (void)clickLeft {
    NSLog(@"点击左边");
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"demo";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"富文本" style:UIBarButtonItemStyleDone target:self action:@selector(clickRight)];
    self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"左边" style:UIBarButtonItemStyleDone target:self action:@selector(clickLeft)];
    
   
    ///点击View
    //    [self cycleTapGES];
    ///视图点击区域
    //    [self cycleExtendTouchRect];
    //导航栏按钮
    //    [self cycleNavBarButtonItem];
    ///时间
    //    [self cycleDate];
    ///字符串相关操作
    //    [self cycleStringTool];
    //点击六边形
//        [self cycleClickSix];
   ///dateFormatter性能优化问题
//    [self cycleDateFormatterperformanceOptimization];
    
    //某个时间范围内
//   BOOL flg = [NSDate cycle_isBetWeenFromHour:9 FromMinute:00 toHour:17 toMinute:00];
    
//    BOOL flg1 = [NSDate cycle_isNotContainWeekendBetWeenFromHour:9 FromMinute:00 toHour:19 toMinute:00];
//    NSLog(@"%d ----- %d",flg,flg1);
    

    
}

///1.点击View
- (void)cycleTapGES{
    self.view.userInteractionEnabled = YES;
    [self.view addGestureRecognizer:[UITapGestureRecognizer cycle_gestureRecognizerWithActionBlock:^(id sender) {
        UITapGestureRecognizer *tap = (UITapGestureRecognizer *)sender;
        if([tap.view isKindOfClass:[UIView class]]){
            NSLog(@"...");
        }
    }]];
}
///2.视图点击区域
- (void)cycleExtendTouchRect {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"点我" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor orangeColor]];
    [button setFrame:CGRectMake(100, 100, 80, 80)];
    [button addTarget:self action:@selector(ClickButton:) forControlEvents:UIControlEventTouchUpInside];
    button.cycle_touchExtendInset = UIEdgeInsetsMake(-20, -20, -200, -20);
    [self.view addSubview:button];
}
- (void)ClickButton:(UIButton*)button{
    NSLog(@"%@",button.currentTitle);
    
}
///3.导航栏按钮
- (void)cycleNavBarButtonItem{
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem cycle_itemWithTarget:self action:@selector(tap:) frame:CGRectMake(0, 0, 44, 44) norImg:@"1.jpg" highImg:@"2.jpg" imgEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}
- (void)tap:(id)item{
    if([item isKindOfClass:[UIButton class]]){
        NSLog(@"is button");
    } else if([item isKindOfClass:[UIBarButtonItem class]]){
        NSLog(@"is UIBarButtonItem");
    }
}
///4.时间
- (void)cycleDate{
    NSString *fuwuqi = @"2018-08-06";
    NSDateFormatter *sdf = [NSDateFormatter new];
    [sdf setDateFormat:@"yyyy-MM-dd"];
    NSDate *fuDate = [sdf dateFromString:fuwuqi];
    if([fuDate cycle_isYesterDay]){
        NSLog(@"昨天");
    }
}
///5.字符串相关操作
- (void)cycleStringTool{
    NSString *str = @"iiiii99090;;'.；】】";
    if([str cycle_isAllChinese]){
        NSLog(@"全部都中文");
    } else {
        NSLog(@"不是全部都中文");
    }
    if([str cycle_isContainChinese]){
        NSLog(@"包含中文");
    } else {
        NSLog(@"不包含中文");
    }
}

///6.点击六边形
- (void)cycleClickSix {
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 400, 200, 200)];
    [imgView cycle_setLayerCornerRadius:100];
    //    imgView.backgroundColor = [UIColor redColor];
    [imgView cycle_setFiveCornerLayerWithView:imgView image:[UIImage imageNamed:@"1.jpg"] cornerColor:[UIColor blueColor] cornerMargin:7.f tapImageViewBlock:^(UIImageView *myView) {
        NSLog(@"...");
    }];
    [self.view addSubview:imgView];
}
///7.DateFormatter性能优化问题
- (void)cycleDateFormatterperformanceOptimization{
    NSDateFormatter *sdf1 = [NSDateFormatter cycle_cachedDateFormatterWithFormatString:@"yyyy:MM:dd"];
    NSLog(@"%@",[sdf1 stringFromDate:[NSDate date]]);
    NSDateFormatter *sdf2 = [NSDateFormatter cycle_cachedDateFormatter];
    [sdf2 setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
    NSLog(@"%@",[sdf2 stringFromDate:[NSDate date]]);
}


@end
